package com.toby.demo.service.impl;

import com.toby.demo.domian.User;
import com.toby.demo.mapper.UserMapper;
import com.toby.demo.service.UserService;
import com.toby.demo.service.PropagationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private PropagationService propagationService;

    @Autowired
    private UserMapper userMapper;

    @Transactional
    @Override
    public void Example1(User user) {
        userMapper.insert(user);
        propagationService.required();
    }

    @Transactional
    @Override
    public void Example2(User user) {
        userMapper.insert(user);
        try {
            propagationService.required();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Transactional
    @Override
    public void Example3(User user) {
        userMapper.insert(user);
        try {
            propagationService.requiresNew();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Transactional
    @Override
    public void Example4(User user) {
        userMapper.insert(user);
        propagationService.requiresNew();
    }

}
